﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Jemgine.MapEditor
{
	public partial class OutputControl : UserControl
	{
		public OutputControl()
		{
			InitializeComponent();
		}

		internal void SetEditorState(EditorState ES)
		{
			foreach (String str in ES._errorBuffer.Messages)
				textBox.AppendText(str);
			ES._errorBuffer.Messages.Clear();

            ES.OnConsoleOutput += AppendText;
		}

        delegate void appendText(string Text);

        void AppendText(string Text)
        {
            if (this.textBox.InvokeRequired)
            {
                var AT = new appendText((A) => { textBox.AppendText(A); this.Invalidate(); });
                this.Invoke(AT, new object[] { Text });
            }
            else
            {
                textBox.AppendText(Text);
                this.Invalidate();
            }
        }
	}
}
